package com.xw.kotlinlib

import android.content.Context
import android.content.SharedPreferences

open class SPUtils(context: Context,spName: String) {

    private var pret: SharedPreferences

    init {
        pret = context.getSharedPreferences(spName,Context.MODE_PRIVATE)
    }

    fun putString(key: String,value: String) {
        pret.edit().putString(key, value).apply()
    }

    fun getString(key: String): String? {
        return pret.getString(key,"")
    }

    fun putBoolean(key: String,value: Boolean) {
        pret.edit().putBoolean(key, value).apply()
    }

    fun getBoolean(key: String): Boolean {
        return pret.getBoolean(key,false)
    }

    fun putFloat(key: String,value: Float) {
        pret.edit().putFloat(key, value).apply()
    }

    fun getFloat(key: String): Float {
        return pret.getFloat(key,0f)
    }

    fun putInt(key: String,value: Int) {
        pret.edit().putInt(key, value).apply()
    }

    fun getInt(key: String): Int {
        return pret.getInt(key,0)
    }

    fun putLong(key: String,value: Long) {
        pret.edit().putLong(key, value).apply()
    }

    fun getLong(key: String): Long {
        return pret.getLong(key,0L)
    }

}